package com.zzs.common.security.config;

import com.zzs.common.security.interceptor.TokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zzs
 * @date 2025/03/17
 */
@Slf4j
@Configuration
@ComponentScan({"com.zzs.common.security.interceptor", "com.zzs.common.security.config"})
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private TokenInterceptor tokenInterceptor;
    @Autowired
    private WhitelistProperties whitelistProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("放行路径: {}", whitelistProperties.getUrls());
        registry.addInterceptor(tokenInterceptor)
//                 放行白名单
                .excludePathPatterns(whitelistProperties.getUrls())
//                 拦截所有路径
                .addPathPatterns("/**");
    }
}
